import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

let temp = sessionStorage.getItem("user");
let token = sessionStorage.getItem("token");

export default new Vuex.Store({
  state: {
    user:temp ? JSON.parse(temp) : {},
    token:token,
    selectUserInfo:{}
  },
  actions: {
    setLoginUser(store,user={}){
      sessionStorage.setItem("user",JSON.stringify(user))
      sessionStorage.setItem("token",user.token)
      
      store.commit("setUser",user)
      store.commit("setToken",user.token)
    }
  },
  getters: {
  },
  mutations: {
    setUser(state,nv){
      state.user = nv;
    },
    setToken(state,nv){
      state.token = nv;
    }
  },
})
